<template>
    <view class="content">
        <view class="nav2-r">
            <view>日期检索</view>
            <view class="time" @click="show = true">
                <view>{{date || '请选择'}}</view>
                <image src="../../static/icon/time.png" class="time-icon"></image>
            </view>
        </view>
        
        <view class="box" v-for="(item, index) in list" :key="index">
            <view class="top">
                <view class="item">
                    <view class="left">费用单据号</view>
                    <view class="right">{{item.cost_number}}</view>
                </view>
                <image src="../../static/icon/del_02.png" class="del-02" @click="del(item)"></image>
            </view>
            <view class="item" v-if="item.out_trade_no">
                <view class="left">运单号</view>
                <view class="right">{{item.out_trade_no}}</view>
            </view>
			<view class="item">
			    <view class="left">申请日期</view>
			    <view class="right">{{item.create_time}}</view>
			</view>
            <view class="item">
                <view class="left">合计金额</view>
                <view class="right">￥{{item.cost}}</view>
            </view>
			<!-- status=1或4 能编辑（车牌号、发货日期不能编辑） -->
            <view class="btns">
                <view class="btn1" v-if="item.status == 1 || item.status == 4" @click="toDetails(item)">编辑</view>
				<view class="btn1" @click="toDetails(item)">查看详情</view>
            </view>
        </view>
		
		<view style="height: 94rpx;padding-top: 30rpx;">
		    <u-loadmore :status="status" v-if="status != 'loadmore'" />
		</view>
        
        <view class="footer" @click="$gTo(`/pages/cost/create`)">添加</view>
		
		<u-picker mode="time" v-model="show" @confirm="confirm"></u-picker>
    </view>
</template>

<script>
    export default {
        data() {
            return {
				show: false,
                date: '',
				status: 'loadmore', //是否显示没有更多了
				page: 1,
				list: [],
            };
        },
		onShow() {
			this.list = []
			this.page = 1
			this.status = 'loadmore'
			this.getList()
		},
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
			del(item) {
				uni.showModal({
					title: '温馨提示',
					content: '确定删除吗？',
					success: (res) => {
						if (res.confirm) {
							this.$ajax('delete_cost_doc', {
								user_token: this.$getSync('userToken'),
								cost_id: item.id,//费用单ID
							}).then(ret => {
								if (ret.success == 1000) {
									this.$toast('删除成功');
									setTimeout(() => {
										this.list = []
										this.page = 1
										this.status = 'loadmore'
										this.getList()
									}, 500)
								} else {
									this.$toast(ret.msg);
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			
			toDetails(item) {
				this.$gTo(`/pages/cost/create?id=${item.id}`)
			},
			
			confirm(e) {
				console.log(e)
				this.date = e.year + '-' + e.month + '-' + e.day
				this.list = []
				this.page = 1
				this.status = 'loadmore'
				this.getList()
			},
			
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('cost_doc', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    date: this.date,//日期搜索 费用单/可添加结算费用单
					type: '',//1 可添加结算费用单
					items_id: '',//搜索项目id 可添加结算费用单
					settlement_id: '',//结算单id 结算单详情
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.cost_doc && ret.detail.cost_doc.length > 0) {
            				this.list = this.list.concat(ret.detail.cost_doc);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #eef1f6;
    }
    .content{
        padding: 20rpx 20rpx 100px;
    }
    .nav2-r{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        font-size: 24rpx;
        color: #737373;
        padding-bottom: 30rpx;
    }
    .time{
        min-width: 210rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #000;
        margin-left: 12rpx;
        padding: 15rpx;
        background-color: #fff;
        border-radius: 10rpx;
    }
    .time-icon{
        width: 25rpx;
        height: 25rpx;
        margin-left: 20rpx;
    }
    
    
    .box{
        padding: 35rpx 30rpx;
        margin-bottom: 15rpx;
        background-color: #fff;
        border-radius: 20rpx;
    }
    .top{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 8rpx;
        font-size: 28rpx;
    }
    .left{
        width: 160rpx;
        color: #656565;
    }
    .right{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }
    .del-02{
        width: 32rpx;
        height: 32rpx;
        margin-left: 15rpx;
    }
    .btns{
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .btn1{
        padding: 15rpx 25rpx;
        background-color: #99aeca;
        border-radius: 50rpx;
        color: #fff;
		margin-left: 20rpx;
    }
    .footer{
        width: 100%;
        height: 90rpx;
        background-color: #00457f;
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        line-height: 90rpx;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 9;
    }

</style>
